{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "import time\n",
    "# https://tushare.pro/document/2?doc_id=135"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = 'E:\\\\HQData\\\\future\\\\'\n",
    "pro = ts.pro_api('0ba8feef618e5db7b1ebb65538fe51e4aef69fb3cbf709d44128f313')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "columns = 'ts_code,symbol,exchange,name,fut_code,multiplier,trade_unit,per_unit,\\\n",
    "quote_unit,quote_unit_desc,d_mode_desc,\\\n",
    "list_date,delist_date,d_month,last_ddate,trade_time_desc'\n",
    "# 合约类型 (1 普通合约 2主力与连续合约 默认取全部)\n",
    "# CFFEX-中金所 DCE-大商所 CZCE-郑商所 SHFE-上期所 INE-上海国际能源交易中心\n",
    "# exchanges=[\"CFFEX\",\"DCE\", \"CZCE\", \"SHFE\", \"INE\"]\n",
    "exchanges=[\"DCE\", \"CZCE\", \"SHFE\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DCE\n",
      "CZCE\n",
      "SHFE\n"
     ]
    }
   ],
   "source": [
    "for exchange in exchanges:\n",
    "    df = pro.fut_basic(exchange = exchange,fut_type= \"1\", fields=columns,fut_code=\"\", list_date='20240101')\n",
    "    #df_dce = pro.fut_basic(exchange='all', fut_type='1', fields=columns,fut_code='',list_date='20240101')\n",
    "    df.to_csv(f'fut_{exchange}.csv',',', encoding='utf_8_sig')\n",
    "    print(exchange)\n",
    "    time.sleep(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "columns = 'ts_code,symbol,exchange,name,fut_code,multiplier,trade_unit,per_unit,\\\n",
    "quote_unit,quote_unit_desc,d_mode_desc,\\\n",
    "list_date,delist_date,d_month,last_ddate,trade_time_desc'\n",
    "# 合约类型 (1 普通合约 2主力与连续合约 默认取全部)\n",
    "# CFFEX-中金所 DCE-大商所 CZCE-郑商所 SHFE-上期所 INE-上海国际能源交易中心\n",
    "df_dce = pro.fut_basic(exchange='DCE', fut_type='1', fields=columns)\n",
    "df_dce.to_csv(path + 'fut_dce.csv',',', encoding='utf_8_sig')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 大商所\n",
    "df_dce = pro.fut_basic(exchange='DCE', fut_type='2', fields=columns)\n",
    "df_dce.to_csv(path + 'fut_main_dce.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_dce = pro.fut_basic(exchange='CZCE', fut_type='2', fields=columns)\n",
    "df_dce.to_csv(path + 'main_CZCE.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 郑商所\n",
    "df_zce = pro.fut_basic(exchange='CZCE', fut_type='1', fields=columns)\n",
    "df_zce.to_csv(path + 'fut_csce.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_zce = pro.fut_basic(exchange='CZCE', fut_type='2', fields=columns)\n",
    "df_zce.to_csv(path + 'main_czce.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上期所\n",
    "df_shfe = pro.fut_basic(exchange='SHFE', fut_type='1', fields=columns)\n",
    "df_shfe.to_csv(path + 'fut_shf.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_shfe = pro.fut_basic(exchange='SHFE', fut_type='2', fields=columns)\n",
    "df_shfe.to_csv(path + 'main_shf.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 中金所\n",
    "df_cffex = pro.fut_basic(exchange='CFFEX', fut_type='1', fields=columns)\n",
    "df_cffex.to_csv(path + 'fut_cffex.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_cffex = pro.fut_basic(exchange='CFFEX', fut_type='2', fields=columns)\n",
    "df_cffex.to_csv(path + 'main_cffex.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上海能源中心\n",
    "df_ine = pro.fut_basic(exchange='INE', fut_type='1', fields=columns)\n",
    "df_ine.to_csv(path + 'fut_ine.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_ine = pro.fut_basic(exchange='INE', fut_type='2', fields=columns)\n",
    "df_ine.to_csv(path + 'main_ine.csv',',', encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>pre_settle</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>settle</th>\n",
       "      <th>change1</th>\n",
       "      <th>change2</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "      <th>oi</th>\n",
       "      <th>oi_chg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211228</td>\n",
       "      <td>69530.0</td>\n",
       "      <td>69730.0</td>\n",
       "      <td>69810.0</td>\n",
       "      <td>70870.0</td>\n",
       "      <td>69700.0</td>\n",
       "      <td>70450.0</td>\n",
       "      <td>70330.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>600.0</td>\n",
       "      <td>91362.0</td>\n",
       "      <td>3212815.87</td>\n",
       "      <td>148144.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211227</td>\n",
       "      <td>69750.0</td>\n",
       "      <td>69790.0</td>\n",
       "      <td>69770.0</td>\n",
       "      <td>69970.0</td>\n",
       "      <td>69490.0</td>\n",
       "      <td>69530.0</td>\n",
       "      <td>69730.0</td>\n",
       "      <td>-260.0</td>\n",
       "      <td>-60.0</td>\n",
       "      <td>60360.0</td>\n",
       "      <td>2104664.47</td>\n",
       "      <td>140027.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211224</td>\n",
       "      <td>70180.0</td>\n",
       "      <td>69960.0</td>\n",
       "      <td>69800.0</td>\n",
       "      <td>70200.0</td>\n",
       "      <td>69470.0</td>\n",
       "      <td>69750.0</td>\n",
       "      <td>69790.0</td>\n",
       "      <td>-210.0</td>\n",
       "      <td>-170.0</td>\n",
       "      <td>83911.0</td>\n",
       "      <td>2928176.94</td>\n",
       "      <td>142606.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211223</td>\n",
       "      <td>69690.0</td>\n",
       "      <td>69500.0</td>\n",
       "      <td>69940.0</td>\n",
       "      <td>70200.0</td>\n",
       "      <td>69790.0</td>\n",
       "      <td>70180.0</td>\n",
       "      <td>69960.0</td>\n",
       "      <td>680.0</td>\n",
       "      <td>460.0</td>\n",
       "      <td>81994.0</td>\n",
       "      <td>2868556.81</td>\n",
       "      <td>144770.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211222</td>\n",
       "      <td>69230.0</td>\n",
       "      <td>69000.0</td>\n",
       "      <td>69340.0</td>\n",
       "      <td>69800.0</td>\n",
       "      <td>69170.0</td>\n",
       "      <td>69690.0</td>\n",
       "      <td>69500.0</td>\n",
       "      <td>690.0</td>\n",
       "      <td>500.0</td>\n",
       "      <td>74042.0</td>\n",
       "      <td>2573015.77</td>\n",
       "      <td>138605.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211221</td>\n",
       "      <td>68630.0</td>\n",
       "      <td>68880.0</td>\n",
       "      <td>68690.0</td>\n",
       "      <td>69300.0</td>\n",
       "      <td>68610.0</td>\n",
       "      <td>69230.0</td>\n",
       "      <td>69000.0</td>\n",
       "      <td>350.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>83762.0</td>\n",
       "      <td>2890048.13</td>\n",
       "      <td>136634.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211220</td>\n",
       "      <td>69370.0</td>\n",
       "      <td>69280.0</td>\n",
       "      <td>69210.0</td>\n",
       "      <td>69460.0</td>\n",
       "      <td>68500.0</td>\n",
       "      <td>68630.0</td>\n",
       "      <td>69010.0</td>\n",
       "      <td>-650.0</td>\n",
       "      <td>-270.0</td>\n",
       "      <td>63223.0</td>\n",
       "      <td>2181565.26</td>\n",
       "      <td>99719.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211217</td>\n",
       "      <td>68590.0</td>\n",
       "      <td>67940.0</td>\n",
       "      <td>69160.0</td>\n",
       "      <td>69560.0</td>\n",
       "      <td>69010.0</td>\n",
       "      <td>69370.0</td>\n",
       "      <td>69280.0</td>\n",
       "      <td>1430.0</td>\n",
       "      <td>1340.0</td>\n",
       "      <td>92896.0</td>\n",
       "      <td>3218182.86</td>\n",
       "      <td>106771.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211216</td>\n",
       "      <td>68000.0</td>\n",
       "      <td>68660.0</td>\n",
       "      <td>67860.0</td>\n",
       "      <td>68760.0</td>\n",
       "      <td>67040.0</td>\n",
       "      <td>68590.0</td>\n",
       "      <td>67940.0</td>\n",
       "      <td>-70.0</td>\n",
       "      <td>-720.0</td>\n",
       "      <td>132546.0</td>\n",
       "      <td>4503120.01</td>\n",
       "      <td>125813.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211215</td>\n",
       "      <td>68910.0</td>\n",
       "      <td>68910.0</td>\n",
       "      <td>69100.0</td>\n",
       "      <td>69150.0</td>\n",
       "      <td>68000.0</td>\n",
       "      <td>68000.0</td>\n",
       "      <td>68660.0</td>\n",
       "      <td>-910.0</td>\n",
       "      <td>-250.0</td>\n",
       "      <td>95585.0</td>\n",
       "      <td>3281452.48</td>\n",
       "      <td>135574.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211214</td>\n",
       "      <td>69570.0</td>\n",
       "      <td>69420.0</td>\n",
       "      <td>69270.0</td>\n",
       "      <td>69350.0</td>\n",
       "      <td>68510.0</td>\n",
       "      <td>68910.0</td>\n",
       "      <td>68910.0</td>\n",
       "      <td>-510.0</td>\n",
       "      <td>-510.0</td>\n",
       "      <td>99921.0</td>\n",
       "      <td>3442845.87</td>\n",
       "      <td>133844.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>CU.SHF</td>\n",
       "      <td>20211213</td>\n",
       "      <td>69530.0</td>\n",
       "      <td>69410.0</td>\n",
       "      <td>69560.0</td>\n",
       "      <td>69660.0</td>\n",
       "      <td>69230.0</td>\n",
       "      <td>69570.0</td>\n",
       "      <td>69420.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>78333.0</td>\n",
       "      <td>2719106.08</td>\n",
       "      <td>136367.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ts_code trade_date  pre_close  pre_settle     open     high      low  \\\n",
       "0   CU.SHF   20211228    69530.0     69730.0  69810.0  70870.0  69700.0   \n",
       "1   CU.SHF   20211227    69750.0     69790.0  69770.0  69970.0  69490.0   \n",
       "2   CU.SHF   20211224    70180.0     69960.0  69800.0  70200.0  69470.0   \n",
       "3   CU.SHF   20211223    69690.0     69500.0  69940.0  70200.0  69790.0   \n",
       "4   CU.SHF   20211222    69230.0     69000.0  69340.0  69800.0  69170.0   \n",
       "5   CU.SHF   20211221    68630.0     68880.0  68690.0  69300.0  68610.0   \n",
       "6   CU.SHF   20211220    69370.0     69280.0  69210.0  69460.0  68500.0   \n",
       "7   CU.SHF   20211217    68590.0     67940.0  69160.0  69560.0  69010.0   \n",
       "8   CU.SHF   20211216    68000.0     68660.0  67860.0  68760.0  67040.0   \n",
       "9   CU.SHF   20211215    68910.0     68910.0  69100.0  69150.0  68000.0   \n",
       "10  CU.SHF   20211214    69570.0     69420.0  69270.0  69350.0  68510.0   \n",
       "11  CU.SHF   20211213    69530.0     69410.0  69560.0  69660.0  69230.0   \n",
       "\n",
       "      close   settle  change1  change2       vol      amount        oi oi_chg  \n",
       "0   70450.0  70330.0    720.0    600.0   91362.0  3212815.87  148144.0   None  \n",
       "1   69530.0  69730.0   -260.0    -60.0   60360.0  2104664.47  140027.0   None  \n",
       "2   69750.0  69790.0   -210.0   -170.0   83911.0  2928176.94  142606.0   None  \n",
       "3   70180.0  69960.0    680.0    460.0   81994.0  2868556.81  144770.0   None  \n",
       "4   69690.0  69500.0    690.0    500.0   74042.0  2573015.77  138605.0   None  \n",
       "5   69230.0  69000.0    350.0    120.0   83762.0  2890048.13  136634.0   None  \n",
       "6   68630.0  69010.0   -650.0   -270.0   63223.0  2181565.26   99719.0   None  \n",
       "7   69370.0  69280.0   1430.0   1340.0   92896.0  3218182.86  106771.0   None  \n",
       "8   68590.0  67940.0    -70.0   -720.0  132546.0  4503120.01  125813.0   None  \n",
       "9   68000.0  68660.0   -910.0   -250.0   95585.0  3281452.48  135574.0   None  \n",
       "10  68910.0  68910.0   -510.0   -510.0   99921.0  3442845.87  133844.0   None  \n",
       "11  69570.0  69420.0    160.0     10.0   78333.0  2719106.08  136367.0   None  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.fut_daily(ts_code='CU.SHF', start_date='20211212', end_date='20211229')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>pre_settle</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>settle</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>5918.0</td>\n",
       "      <td>5934.0</td>\n",
       "      <td>5907.0</td>\n",
       "      <td>5978.0</td>\n",
       "      <td>5891.0</td>\n",
       "      <td>5962.0</td>\n",
       "      <td>5929.0</td>\n",
       "      <td>126232.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A2201.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>6077.0</td>\n",
       "      <td>6091.0</td>\n",
       "      <td>6091.0</td>\n",
       "      <td>6091.0</td>\n",
       "      <td>6057.0</td>\n",
       "      <td>6079.0</td>\n",
       "      <td>6073.0</td>\n",
       "      <td>1856.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2203.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>5918.0</td>\n",
       "      <td>5934.0</td>\n",
       "      <td>5907.0</td>\n",
       "      <td>5978.0</td>\n",
       "      <td>5891.0</td>\n",
       "      <td>5962.0</td>\n",
       "      <td>5929.0</td>\n",
       "      <td>126232.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A2205.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>5952.0</td>\n",
       "      <td>5965.0</td>\n",
       "      <td>5954.0</td>\n",
       "      <td>6027.0</td>\n",
       "      <td>5936.0</td>\n",
       "      <td>5996.0</td>\n",
       "      <td>5971.0</td>\n",
       "      <td>20737.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A2207.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>5934.0</td>\n",
       "      <td>5945.0</td>\n",
       "      <td>5941.0</td>\n",
       "      <td>6004.0</td>\n",
       "      <td>5918.0</td>\n",
       "      <td>5971.0</td>\n",
       "      <td>5946.0</td>\n",
       "      <td>8219.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>Y2208.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>8314.0</td>\n",
       "      <td>8272.0</td>\n",
       "      <td>8282.0</td>\n",
       "      <td>8440.0</td>\n",
       "      <td>8282.0</td>\n",
       "      <td>8380.0</td>\n",
       "      <td>8376.0</td>\n",
       "      <td>5909.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>Y2209.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>8240.0</td>\n",
       "      <td>8208.0</td>\n",
       "      <td>8260.0</td>\n",
       "      <td>8362.0</td>\n",
       "      <td>8250.0</td>\n",
       "      <td>8302.0</td>\n",
       "      <td>8304.0</td>\n",
       "      <td>6178.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>Y2211.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>8156.0</td>\n",
       "      <td>8124.0</td>\n",
       "      <td>8186.0</td>\n",
       "      <td>8298.0</td>\n",
       "      <td>8184.0</td>\n",
       "      <td>8238.0</td>\n",
       "      <td>8242.0</td>\n",
       "      <td>2184.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>260</th>\n",
       "      <td>Y2212.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>8164.0</td>\n",
       "      <td>8106.0</td>\n",
       "      <td>8230.0</td>\n",
       "      <td>8230.0</td>\n",
       "      <td>8214.0</td>\n",
       "      <td>8214.0</td>\n",
       "      <td>8222.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>YL.DCE</td>\n",
       "      <td>20211223</td>\n",
       "      <td>8958.0</td>\n",
       "      <td>8958.0</td>\n",
       "      <td>8988.0</td>\n",
       "      <td>9112.0</td>\n",
       "      <td>8958.0</td>\n",
       "      <td>9072.0</td>\n",
       "      <td>9048.0</td>\n",
       "      <td>50694.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>262 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       ts_code trade_date  pre_close  pre_settle    open    high     low  \\\n",
       "0        A.DCE   20211223     5918.0      5934.0  5907.0  5978.0  5891.0   \n",
       "1    A2201.DCE   20211223     6077.0      6091.0  6091.0  6091.0  6057.0   \n",
       "2    A2203.DCE   20211223     5918.0      5934.0  5907.0  5978.0  5891.0   \n",
       "3    A2205.DCE   20211223     5952.0      5965.0  5954.0  6027.0  5936.0   \n",
       "4    A2207.DCE   20211223     5934.0      5945.0  5941.0  6004.0  5918.0   \n",
       "..         ...        ...        ...         ...     ...     ...     ...   \n",
       "257  Y2208.DCE   20211223     8314.0      8272.0  8282.0  8440.0  8282.0   \n",
       "258  Y2209.DCE   20211223     8240.0      8208.0  8260.0  8362.0  8250.0   \n",
       "259  Y2211.DCE   20211223     8156.0      8124.0  8186.0  8298.0  8184.0   \n",
       "260  Y2212.DCE   20211223     8164.0      8106.0  8230.0  8230.0  8214.0   \n",
       "261     YL.DCE   20211223     8958.0      8958.0  8988.0  9112.0  8958.0   \n",
       "\n",
       "      close  settle       vol  \n",
       "0    5962.0  5929.0  126232.0  \n",
       "1    6079.0  6073.0    1856.0  \n",
       "2    5962.0  5929.0  126232.0  \n",
       "3    5996.0  5971.0   20737.0  \n",
       "4    5971.0  5946.0    8219.0  \n",
       "..      ...     ...       ...  \n",
       "257  8380.0  8376.0    5909.0  \n",
       "258  8302.0  8304.0    6178.0  \n",
       "259  8238.0  8242.0    2184.0  \n",
       "260  8214.0  8222.0       2.0  \n",
       "261  9072.0  9048.0   50694.0  \n",
       "\n",
       "[262 rows x 10 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取2018年11月13日大商所全部合约行情数据\n",
    "df = pro.fut_daily(trade_date='20211223', exchange='DCE', fields='ts_code,trade_date,pre_close,pre_settle,open,high,low,close,settle,vol')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "pro.fut_daily?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>exchange</th>\n",
       "      <th>name</th>\n",
       "      <th>fut_code</th>\n",
       "      <th>multiplier</th>\n",
       "      <th>trade_unit</th>\n",
       "      <th>per_unit</th>\n",
       "      <th>quote_unit</th>\n",
       "      <th>quote_unit_desc</th>\n",
       "      <th>d_mode_desc</th>\n",
       "      <th>list_date</th>\n",
       "      <th>delist_date</th>\n",
       "      <th>d_month</th>\n",
       "      <th>last_ddate</th>\n",
       "      <th>trade_time_desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>JD1907.DCE</td>\n",
       "      <td>JD1907</td>\n",
       "      <td>DCE</td>\n",
       "      <td>鸡蛋1907</td>\n",
       "      <td>JD</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>5.0</td>\n",
       "      <td>人民币元/500千克</td>\n",
       "      <td>1人民币元/500千克</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20180727</td>\n",
       "      <td>20190726</td>\n",
       "      <td>201907</td>\n",
       "      <td>20190731</td>\n",
       "      <td>上午9:00-11:30，下午13:30-15:00，以及交易所规定的其他时间</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CS1505.DCE</td>\n",
       "      <td>CS1505</td>\n",
       "      <td>DCE</td>\n",
       "      <td>玉米淀粉1505</td>\n",
       "      <td>CS</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>1人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20141219</td>\n",
       "      <td>20150515</td>\n",
       "      <td>201505</td>\n",
       "      <td>20150520</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>JM2304.DCE</td>\n",
       "      <td>JM2304</td>\n",
       "      <td>DCE</td>\n",
       "      <td>焦煤2304</td>\n",
       "      <td>JM</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>60.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>0.5人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20220419</td>\n",
       "      <td>20230417</td>\n",
       "      <td>202304</td>\n",
       "      <td>20230420</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>C1003.DCE</td>\n",
       "      <td>C1003</td>\n",
       "      <td>DCE</td>\n",
       "      <td>玉米1003</td>\n",
       "      <td>C</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>1人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20090316</td>\n",
       "      <td>20100312</td>\n",
       "      <td>201003</td>\n",
       "      <td>20100316</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>M1708.DCE</td>\n",
       "      <td>M1708</td>\n",
       "      <td>DCE</td>\n",
       "      <td>豆粕1708</td>\n",
       "      <td>M</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>1人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20160815</td>\n",
       "      <td>20170814</td>\n",
       "      <td>201708</td>\n",
       "      <td>20170817</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2901</th>\n",
       "      <td>Y2412.DCE</td>\n",
       "      <td>Y2412</td>\n",
       "      <td>DCE</td>\n",
       "      <td>豆油2412</td>\n",
       "      <td>Y</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>2人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20231215</td>\n",
       "      <td>20241213</td>\n",
       "      <td>202412</td>\n",
       "      <td>20241218</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2902</th>\n",
       "      <td>P2406.DCE</td>\n",
       "      <td>P2406</td>\n",
       "      <td>DCE</td>\n",
       "      <td>棕榈油2406</td>\n",
       "      <td>P</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>2人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20230615</td>\n",
       "      <td>20240617</td>\n",
       "      <td>202406</td>\n",
       "      <td>20240620</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2903</th>\n",
       "      <td>JM1611.DCE</td>\n",
       "      <td>JM1611</td>\n",
       "      <td>DCE</td>\n",
       "      <td>焦煤1611</td>\n",
       "      <td>JM</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>60.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>0.5人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20151116</td>\n",
       "      <td>20161114</td>\n",
       "      <td>201611</td>\n",
       "      <td>20161117</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2904</th>\n",
       "      <td>EG2405.DCE</td>\n",
       "      <td>EG2405</td>\n",
       "      <td>DCE</td>\n",
       "      <td>乙二醇2405</td>\n",
       "      <td>EG</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>1人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20230529</td>\n",
       "      <td>20240528</td>\n",
       "      <td>202405</td>\n",
       "      <td>20240531</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2905</th>\n",
       "      <td>B1007.DCE</td>\n",
       "      <td>B1007</td>\n",
       "      <td>DCE</td>\n",
       "      <td>豆二1007</td>\n",
       "      <td>B</td>\n",
       "      <td>None</td>\n",
       "      <td>吨</td>\n",
       "      <td>10.0</td>\n",
       "      <td>人民币元/吨</td>\n",
       "      <td>1人民币元/吨</td>\n",
       "      <td>实物交割</td>\n",
       "      <td>20090715</td>\n",
       "      <td>20100714</td>\n",
       "      <td>201007</td>\n",
       "      <td>20100719</td>\n",
       "      <td>上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2906 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         ts_code  symbol exchange      name fut_code multiplier trade_unit  \\\n",
       "0     JD1907.DCE  JD1907      DCE    鸡蛋1907       JD       None          吨   \n",
       "1     CS1505.DCE  CS1505      DCE  玉米淀粉1505       CS       None          吨   \n",
       "2     JM2304.DCE  JM2304      DCE    焦煤2304       JM       None          吨   \n",
       "3      C1003.DCE   C1003      DCE    玉米1003        C       None          吨   \n",
       "4      M1708.DCE   M1708      DCE    豆粕1708        M       None          吨   \n",
       "...          ...     ...      ...       ...      ...        ...        ...   \n",
       "2901   Y2412.DCE   Y2412      DCE    豆油2412        Y       None          吨   \n",
       "2902   P2406.DCE   P2406      DCE   棕榈油2406        P       None          吨   \n",
       "2903  JM1611.DCE  JM1611      DCE    焦煤1611       JM       None          吨   \n",
       "2904  EG2405.DCE  EG2405      DCE   乙二醇2405       EG       None          吨   \n",
       "2905   B1007.DCE   B1007      DCE    豆二1007        B       None          吨   \n",
       "\n",
       "      per_unit  quote_unit quote_unit_desc d_mode_desc list_date delist_date  \\\n",
       "0          5.0  人民币元/500千克     1人民币元/500千克        实物交割  20180727    20190726   \n",
       "1         10.0      人民币元/吨         1人民币元/吨        实物交割  20141219    20150515   \n",
       "2         60.0      人民币元/吨       0.5人民币元/吨        实物交割  20220419    20230417   \n",
       "3         10.0      人民币元/吨         1人民币元/吨        实物交割  20090316    20100312   \n",
       "4         10.0      人民币元/吨         1人民币元/吨        实物交割  20160815    20170814   \n",
       "...        ...         ...             ...         ...       ...         ...   \n",
       "2901      10.0      人民币元/吨         2人民币元/吨        实物交割  20231215    20241213   \n",
       "2902      10.0      人民币元/吨         2人民币元/吨        实物交割  20230615    20240617   \n",
       "2903      60.0      人民币元/吨       0.5人民币元/吨        实物交割  20151116    20161114   \n",
       "2904      10.0      人民币元/吨         1人民币元/吨        实物交割  20230529    20240528   \n",
       "2905      10.0      人民币元/吨         1人民币元/吨        实物交割  20090715    20100714   \n",
       "\n",
       "     d_month last_ddate                               trade_time_desc  \n",
       "0     201907   20190731       上午9:00-11:30，下午13:30-15:00，以及交易所规定的其他时间  \n",
       "1     201505   20150520  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "2     202304   20230420  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "3     201003   20100316  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "4     201708   20170817  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "...      ...        ...                                           ...  \n",
       "2901  202412   20241218  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "2902  202406   20240620  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "2903  201611   20161117  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "2904  202405   20240531  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "2905  201007   20100719  上午9:00-11:30,下午13:30-15:00,下午21:00-23:00(夜盘)  \n",
       "\n",
       "[2906 rows x 16 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_dce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 南华指数\n",
    "df = pro.index_daily(ts_code='CU.NH', start_date='20180101', end_date='20181201')\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
